package team.yidong.fenda.Scheduling;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import team.yidong.fenda.service.GuahaoService;
import team.yidong.fenda.service.MasterScoreService;
import team.yidong.fenda.service.WxOrderService;

/**
 * Created by xuanlong on 2017/12/20.
 */
@Configuration
@EnableScheduling
public class ScheduledTasks {
    private final static Logger logger = LoggerFactory.getLogger(ScheduledTasks.class);
    @Autowired
    WxOrderService wxOrderService;
    @Autowired
    MasterScoreService masterScoreService;
    @Autowired
    GuahaoService guahaoService;

    /**
     * 每天凌晨两点检测三天前的订单，进行分积分操作
     */
    @Scheduled(cron = "0 25 18 * * ?")
    public void wxOrderHandle() {
        logger.info("start dingshi");
        wxOrderService.wxOrderHandle();
    }

    /**
     * 每一个月进行一次对专家的积分提现
     */
    @Scheduled(cron = "0 0 0 1 1/1 ? ")
    public void masterScoreToMoney1() {
        masterScoreService.masterScoreToMoney(1);
    }

    /**
     * 每三个月进行一次对专家的积分提现
     */
    @Scheduled(cron = "0 0 0 1 1/3 ? ")
    public void masterScoreToMoney2() {
        masterScoreService.masterScoreToMoney(3);
    }

    /**
     * 每六个月进行一次对专家的积分提现
     */
    @Scheduled(cron = "0 0 0 1 1/6 ? ")
    public void masterScoreToMoney3() {
        masterScoreService.masterScoreToMoney(6);
    }

    /**
     * 每十二个月进行一次对专家的积分提现
     */
    @Scheduled(cron = "0 0 0 1 1/12 ? ")
    public void masterScoreToMoney4() {
        masterScoreService.masterScoreToMoney(12);
    }

    /**
     * 每天0点 新增第七天挂号置0
     */
    @Scheduled(cron = "0 0 0 1/1 * ? ")
    private void addSevenDayGuahao() {
        guahaoService.addSevenDayGuahao();
    }
}